package com.amaze.escape.player;

import org.lwjgl.util.vector.Vector3f;

import com.amaze.escape.util.VectorPool;

/**
 * Represents the position of a block. This class is used within the
 * collision detection process.
 * 
 * @author Amaze Team
 */
public final class BlockPosition implements Comparable<BlockPosition> {

    /**
     * Position on the x-axis.
     */
    /**
     * Position on the y-axis.
     */
    /**
     * Position on the z-axis.
     */
    public int x, y, z;
    private Vector3f _origin;

    /**
     * 
     * @param x
     * @param y
     * @param z
     * @param origin
     */
    public BlockPosition(int x, int y, int z, Vector3f origin) {
        this.x = x;
        this.y = y;
        this.z = z;
        this._origin = origin;
    }

    /**
     * 
     * @param origin
     */
    public void setOrigin(Vector3f origin) {
        this._origin = origin;
    }

    /**
     * 
     * @return
     */
    public Vector3f getOrigin() {
        return _origin;
    }

    /**
     * 
     * @return
     */
    public float getDistance() {
        return VectorPool.getVector((float) x - _origin.x, (float) y - _origin.y, (float) z - _origin.z).lengthSquared();
    }

    /**
     * 
     * @param o
     * @return
     */
    @Override
    public int compareTo(BlockPosition o) {
        return new Float(getDistance()).compareTo(new Float(o.getDistance()));
    }
}
